package kr.pe.johnkim.app.mobile.rest.dao;

import kr.pe.johnkim.app.domain.MyHistoryCategory;
import kr.pe.johnkim.app.domain.MyHistoryGroup;
import kr.pe.johnkim.app.domain.MyHistoryGroupRelation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * @author : johnkim <cale9797@gmail.com / Simple.ly Inc,>
 * @Date : 12. 1. 4
 */
public class MyHistoryGroupRelationDaoImpl extends SqlMapClientDaoSupport implements MyHistoryGroupRelationDao {
    // SLF4J Logging
	private Logger logger = LoggerFactory.getLogger(MyHistoryGroupRelationDaoImpl.class);

    /**
     * 카테고리를 그룹에 연결 한다.
     *
     * @param myHistoryGroupRelation
     * @return True or False
     */
    public boolean registerRelation(MyHistoryGroupRelation myHistoryGroupRelation) {
        logger.info("registerRelation");

        boolean result = false;

        try {
            getSqlMapClientTemplate().insert("MYHISTORY_GROUP_RELATION.registerRelation", myHistoryGroupRelation);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 카테고리를 그룹에 연결 해제 한다.
     *
     * @param myHistoryGroupRelation
     * @return True or False
     */
    public boolean updateDeactivateRelation(MyHistoryGroupRelation myHistoryGroupRelation) {
        logger.info("updateDeactivateRelation");

        boolean result = false;

        try {
            getSqlMapClientTemplate().update("MYHISTORY_GROUP_RELATION.updateDeactivateRelation", myHistoryGroupRelation);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 카테고리에 연결된 그룹 목록을 가져 온다.
     *
     * @param myHistoryGroupRelation
     * @return List<MyHistoryGroup>
     */
    public List<MyHistoryGroup> selectRelationGroupList(MyHistoryGroupRelation myHistoryGroupRelation) {
        logger.info("selectRelationGroupList");
        return this.getSqlMapClientTemplate().queryForList("MYHISTORY_GROUP_RELATION.selectRelationGroupList", myHistoryGroupRelation);
    }

    /**
     * 그룹에 연결된 카테고리 목록을 가져 온다.
     *
     * @param myHistoryGroupRelation
     * @return List<MyHistoryCategory>
     */
    public List<MyHistoryCategory> selectRelationCategoryList(MyHistoryGroupRelation myHistoryGroupRelation) {
        logger.info("selectRelationCategoryList");
        return this.getSqlMapClientTemplate().queryForList("MYHISTORY_GROUP_RELATION.selectRelationCategoryList", myHistoryGroupRelation);
    }
}
